home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 151-175 / disk_171 / sozobon-c / libs / gifts / gifts.zoo / echo.c next >
C/C++ Source or Header  |  1988-11-09  |  1KB  |  70 lines

  1. #include <stdio.h>
  2. #include <errno.h>
  3.  
  4. int    n_flag = FALSE;        /* suppress '\n' after output */
  5. int    c_flag = FALSE;        /* process words with ctlcnv() */
  6.  
  7. usage()
  8.     {
  9.     fprintf(stderr, "usage: echo [-nc] [-ofile|-afile] [--] [word...]\n");
  10.     exit(1);
  11.     }
  12.  
  13. main(argc, argv)
  14.     int argc;
  15.     char *argv[];
  16.     {
  17.     extern int optind;
  18.     extern char *optarg;
  19.     register int c;
  20.     register char *p;
  21.  
  22.     while((c = getopt(argc, argv, "nco:a:E")) != EOF)
  23.         {
  24.         switch(c)
  25.             {
  26.             case 'n':
  27.                 n_flag = TRUE;
  28.                 break;
  29.             case 'c':
  30.                 c_flag = TRUE;
  31.                 break;
  32.             case 'o':
  33.                 if(freopen(optarg, "w", stdout) == NULL)
  34.                     {
  35.                     perrorf(
  36.                     "can write to file '%s', errno=%d",
  37.                         optarg, errno);
  38.                     exit(EXIT_FAILURE);
  39.                     }
  40.                 break;
  41.             case 'a':
  42.                 if(freopen(optarg, "a", stdout) == NULL)
  43.                     {
  44.                     perrorf(
  45.                     "can append to file '%s', errno=%d",
  46.                         optarg, errno);
  47.                     exit(EXIT_FAILURE);
  48.                     }
  49.                 break;
  50.             case 'E':
  51.                 for(c = 0; is_syserr(c); --c)
  52.                     printf("error %-3d '%s'\n",
  53.                         c, strerror(c));
  54.                 exit(EXIT_SUCCESS);
  55.             case '?':
  56.                 usage();
  57.             }
  58.         }
  59.     for(; optind < argc; ++optind)
  60.         {
  61.         p = argv[optind];
  62.         if(c_flag)
  63.             ctlcnv(p);
  64.         fputs(p, stdout);
  65.         fputc(' ', stdout);
  66.         }
  67.     if(!n_flag)
  68.         fputc('\n', stdout);
  69.     }
  70.